package cn.lanqiao.facelogin.controller;

import cn.lanqiao.facelogin.BaiDuFace.*;
import cn.lanqiao.facelogin.domain.JsonResult;
import cn.lanqiao.facelogin.domain.LoginData;
import cn.lanqiao.facelogin.domain.ResParameter;
import cn.lanqiao.facelogin.domain.Result;
import cn.lanqiao.facelogin.faceData.Base64Convert;
import cn.lanqiao.facelogin.service.LoginService;
import cn.lanqiao.facelogin.utils.BASE64SaveToLocalImage;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.time.FastDateFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/login")
@Api(tags = "用户登录")
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/sendCode")
    @ApiOperation("发送验证码")
    @ApiImplicitParam(name = "tel", value = "电话号", required = true)
    public Result getVerificationCode(@RequestBody String tel) {
        String telNew = JSONObject.parseObject(tel).getString("tel");
        return loginService.sendTheVerificationCode(telNew);
    }

    @PostMapping("/phoneVerification")
    @ApiOperation("电话验证")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tel", value = "电话号", required = true),
            @ApiImplicitParam(name = "telCode", value = "验证码", required = true),
    })
    public Result phoneVerification(@RequestBody String tel) {
        String telNew = JSONObject.parseObject(tel).getString("tel");
        String telCodeNew = JSONObject.parseObject(tel).getString("telCode");
        return loginService.saveThePhoneNumber(telNew, telCodeNew);
    }

    @PostMapping("/giteeSave")
    @ApiOperation("码云用户信息保存")
    public Result giteeSave(String tel, String telCode, String uName, String tokenId) {
        return loginService.giteeSave(tel, telCode, uName, tokenId);
    }
}
